package com.zuoye.day12;


import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;


public class TestOrderCus {
    public static void main(String[] args) {

       // (1) 使用ArrayList 将用户smith 的三个订单添加到 ArrayList  集合中
       Customer customer = new Customer("smith");
       MyOrder myOrder1 = new MyOrder(1,"1234",153,LocalDateTime.of(2022,3,1,12,23,45),customer);
       MyOrder myOrder2 = new MyOrder(2,"12345",54342,LocalDateTime.of(2022,7,22,8,45,23),customer);
       MyOrder myOrder3 = new MyOrder(3,"12311",5354,LocalDateTime.now(),customer);
       List<MyOrder> list = new ArrayList<>();
       list.add(myOrder1);
       list.add(myOrder2);
       list.add(myOrder3);
       System.out.println(list);

       //统计smith所有订单的总价格
        double sumPrice = 0.0;
        for (MyOrder myOrder : list){
            sumPrice += myOrder.getOrderSumPrice();
        }
        System.out.println("总价格" + sumPrice);


        //查询出在2022-5-1之前的订单信息
       DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        for (MyOrder myOrder : list) {
            if (myOrder.getCreatDateTime().toLocalDate().isBefore(LocalDate.parse("2022-05-01", dateTimeFormatter))) {
                System.out.println(myOrder);
            }

        }


    }

}
